﻿using System;
using System.IO;
using System.Reflection;

namespace CustomerContactSystem.PollingApp {
    class Program {
        static void Main() {
            var executingPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var errorLog = new StreamWriter(executingPath + @"\CustomerContactSystemPollerLog.txt");
            try {
                var ccsService = new CcsService.CustomerContactSystemService();
                Console.WriteLine("Importing new incidents...");
                ccsService.ImportNewFixYourStreetIncidents();
                Console.WriteLine("Importing new incidents...done");
                Console.WriteLine("Importing new comments...");
                ccsService.ImportNewFixYourStreetComments();
                Console.WriteLine("Importing new comments...done");
                Console.WriteLine("Importing sending comments to Fix Your Street...");
                ccsService.ExportPendingComments();
                Console.WriteLine("Importing sending comments to Fix Your Street...");
                Console.WriteLine("Importing sending status updates to Fix Your Street...");
                ccsService.ExportPendingStatusUpdates();
                Console.WriteLine("Importing sending status updates to Fix Your Street...done");
                Console.WriteLine("Sending pending emails...");
                ccsService.SendPendingEmails();
                Console.WriteLine("Sending pending emails...done");
            } catch (Exception ex) {
                errorLog.Write(ex.Message);
            } finally {
                errorLog.Close();
            }
        }
    }
}
